﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    var isJump = false;
    var currRowId = 0;
    $(function () {
        initControl();
        treeView();
        gridList();
        $('.bbit-tree-node-el[title=冲压件库货位存储策略]').addClass("bbit-tree-selected");
    });
    function initControl() {
        var myLayout = $('#layout').layout({ resizable: false });
        myLayout.sizePane("west", 200);
    }
    function treeView() {
        $("#itemTree").treeview({
            url: "/MainData/Storage/GetStrategyJson",
            onnodeclick: function (item) {
                //alert(item.value);
                if (item.value != '') {
                    location.href = '/MainData/Storage/' + item.value;
                }
            }
        });
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/MainData/Storage/GetStrategyCPJson",
            height: $(window).height() - 126,
            colModel: [
                {
                    label: '货位类型', name: 'FStoType', width: 130, align: 'left', sortable: false, frozen: true, formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == "1" ? "1-区号-按平面存放" : cellvalue == "2" ? "2-架号-按货架存放" : cellvalue == "3" ? "3-层号-按分层存放" : cellvalue == "4" ? "4-单元-按货架单元" : cellvalue == "5" ? "5-单元-按存储单元" : "";
                    }
                },
                { label: '仓库名称', name: 'FStoreName', width: 100, align: 'left', sortable: false, frozen: true },
                { label: '货位编号', name: 'FStoreSetNO', width: 160, align: 'left', sortable: false, frozen: true },
                //{ label: '货架编号', name: '', width: 80, align: 'center', sortable: false },
                //{ label: '层数',     name: '', width: 80, align: 'center', sortable: false },
                //{ label: '列数',     name: '', width: 80, align: 'center', sortable: false },
                //{ label: '货架层号', name: '', width: 80, align: 'center', sortable: false },
                //{ label: '货架列号', name: '', width: 80, align: 'center', sortable: false },
                {
                    label: '优先级别', name: 'FLevel', width: 130, align: 'left', sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == "1" ? "1-一级-主要存储区" : cellvalue == "2" ? "2-二级-中转存储区" : cellvalue == "3" ? "3-三级-临时存储区" : "";
                    }
                },
                {
                    label: '使用标志', name: 'FEnableSign', width: 80, align: 'center', sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == "0" ? "0-封存" : cellvalue == "1" ? "1-在用" : "";
                    }
                },
                { label: '货位说明', name: 'FStoreDesc', width: 180, align: 'left', sortable: false },
                {
                    label: '推荐方式', name: 'FStorageSign', width: 110, align: 'left', sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == "1" ? "1-按零件推荐" : cellvalue == "2" ? "2-按容器推荐" : cellvalue == "3" ? "3-按供应商推荐" : "";
                    }
                },
                { label: '创建人员', name: 'FCreateBy', width: 80, align: 'left', sortable: false },
                { label: '创建日期', name: 'FCreateDate', width: 80, align: 'center', sortable: false },
                { label: '创建时间', name: 'FCreateTime', width: 80, align: 'center', sortable: false },
                { label: '更改人员', name: 'FUpdateBy', width: 80, align: 'left', sortable: false },
                { label: '更改日期', name: 'FUpdateDate', width: 80, align: 'center', sortable: false },
                { label: '更改时间', name: 'FUpdateTime', width: 80, align: 'center', sortable: false },
                { label: '仓库编码', name: 'FStoreNO', width: 80, align: 'center', hidden: true },
                { label: '货位ID', name: 'FStoreSetID', width: 80, align: 'center', hidden: true },
            ],
            pager: "#gridPager",
            sortname: 'FStoreSetNO ASC',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                var rowDatas = $gridList.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList.jqGrid('setSelection', currRowId);
                    var $grid = $('#gview_gridList .ui-jqgrid-bdiv');
                    if (isJump) {
                        $grid.setScrollTop(length, currRowId);
                        isJump = false;
                    } else {
                        var top = $grid.scrollTop();
                        $grid.scrollTop(top + 1);
                    }
                }
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
                $('#btn_remove').removeClass("disabled");
                $('#btn_edit').removeClass("disabled");
            },
            onPaging: function (page_btn) {
                currRowId = 0;
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            reloadGrid();
        });
    }
    function reloadGrid(currNumber) {
        currNumber = currNumber || '';
        var currPage = 1;
        if (currNumber != "") {
            //var data = $("#form1").formSerialize();
            var data = {};
            var page = $('#gridList').getGridParam('page'); // current page  
            var rows = $('#gridList').getGridParam('rowNum'); // rows    
            var sidx = $('#gridList').getGridParam('sortname'); // sidx  
            var sord = $('#gridList').getGridParam('sortorder'); // sord  
            data["sidx"] = sidx;
            data["sord"] = sord;
            data["rows"] = rows;
            data["currNumber"] = currNumber;
            $.ajaxSetup({ async: false });
            $.getJSON("/MainData/Storage/GetStrategyCPSortJson", data, function (result) {
                currPage = result.currPage;
                currRowId = result.currIndex;
            });
            $.ajaxSetup({ async: true });
            emptyDataById("#form1");
            isJump = true;
            $("#gridList").jqGrid('setGridParam', {
                page: currPage,
            }).trigger('reloadGrid');
        } else {
            isJump = false;
            $("#gridList").jqGrid('setGridParam', {
                postData: $("#form1").formSerialize(),
            }).trigger('reloadGrid');
        }
    }
    function btn_add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/MainData/Storage/StrategyCPInput"
        });
    }
    function btn_edit() {
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/MainData/Storage/StrategyCPInput?status=U&number=" + rowData.FStoreSetID
        });
    }
    function btn_remove() {
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        $.modalConfirm("注：您确定要【删除】该条数据吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/MainData/Storage/SubmitStrategyCPForm?status=D",
                    param: { keyValue: rowData.FStoreSetID },
                    success: function () {
                        reloadGrid();
                    }
                })
            }
        });
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div id="itemTree"></div>
    </div>
    <div class="ui-layout-center">
        <form id="form1">
            <div style="padding: 12px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc;" class="line-table input-width-140">
                <div class="btn-group" style="margin-top:-9px;">
                    仓库名称<br /><input id="FStoreName" name="FStoreName" type="text" class="form-control" /> &nbsp;
                </div>
                <div class="btn-group" style="margin-top:-9px;">
                    货位编号<br /><input id="FStoreSetNO" name="FStoreSetNO" type="text" class="form-control" /> &nbsp;
                </div>
                <div class="btn-group" style="">
                    <a id="btn_search" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span> 检索</a>
                </div>
                <div class="btn-group" style="float:right;">
                    <a id="" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                    <a id="btn_add" class="btn btn-primary center-block" onclick="btn_add()"><span class="glyphicon glyphicon-plus"></span> 新增</a>
                    <a id="btn_remove" class="btn btn-primary center-block disabled" onclick="btn_remove()"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                    <a id="btn_edit" class="btn btn-primary center-block disabled" onclick="btn_edit()"><span class="glyphicon glyphicon-edit"></span> 修改</a>
                    <a id="btn_export" class="btn btn-primary center-block" onclick="btn_export()"><span class="glyphicon glyphicon-download"></span> 导出</a>
                </div>
            </div>
        </form>
        <div style="">
            <table id="gridList"></table>
            <div id="gridPager"></div>
        </div>        
    </div>

</div>

